//
//  mainViewController.m
//  blackjack
//
//  Created by Thi Nguyen Tran on 3/13/10.
//  Copyright 2010 Epsilon. All rights reserved.
//

#import "mainViewController.h"
#import "CountingSystemController.h"
#import "BasicStrategyMainViewController.h"
#import "InforViewController.h"
#import "constants.h"
#import "Dealer.h"
#import "TutorMainControl.h"
//#define DEBUG_LOADING
#define DEBUG_MAIN_MENU

@interface MainViewController (Private)

CountingSystemController		*countController_;
BasicStrategyMainViewController *basicController_;
InforViewController				*inforController_;
TutorMainControl				*tutorContorller_;

- (void)setLandscapeToView:(UIView *) v;
@end


@implementation MainViewController

-(id)init {
	if(self = [super init]) {
		loading_ = [[LoadingController alloc] init];
		[loading_ setDelegate:self];
		self.view = loading_.view;
	}
	return self;
}

- (void)endLoading
{
	if(!menus_) {
		menus_ = [[MainMenuController alloc] init];
		menus_.delegate = self;
	}
	
	self.view = menus_.view;
	[loading_ release];
}

- (void)backToMainMenu {
	if(!menus_) {
		menus_ = [[MainMenuController alloc] init];
		menus_.delegate = self;
	}
	[self setLandscapeToView:self.view];
	self.view = menus_.view;
	if(basicController_) [basicController_ release];
	if(tutorContorller_)  [tutorContorller_ release];
	if(countController_) [countController_ release];
	if(inforController_) [inforController_ release];
}

- (void)chooseMode:(int)m {
	switch (m) {
		case BASIC_STRATEGY:
			basicController_ = [[BasicStrategyMainViewController alloc] init];
			[basicController_ setDelegate:self];
			self.view = basicController_.view;
			break;
		case TUTORIAL_AND_TIPS:
			tutorContorller_ = [[TutorMainControl alloc] init] ;;
			[tutorContorller_ setDelegate:self];
			self.view = tutorContorller_.view;
			break;
		case CARD_COUNTING:
			countController_ = [[CountingSystemController alloc] init];
			[countController_ setDelegate_:self];
			self.view = countController_.view;
			break;
		case INFORMATION:
			inforController_ = [[InforViewController alloc] init];
			[inforController_ setDelegate:self];
			self.view = inforController_.view;
			break;
		default:
			break;
	}
}

- (void)setLandscapeToView:(UIView *)view
{
	[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortraitUpsideDown animated:NO];
	CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(M_PI_2);
	landscapeTransform = CGAffineTransformTranslate (landscapeTransform, +80.0, +100.0);
	[self.view setTransform:landscapeTransform];
	
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)dealloc {
    [super dealloc];
}


@end
